package com.dm.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dm.R;
import com.dm.R.color;
import com.dm.bean.SpAlarmItem;

public class SpAlarmAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<SpAlarmItem> list;
    private LayoutInflater inflater = null;

    public SpAlarmAdapter(Context context, ArrayList<SpAlarmItem> list) {
	this.context = context;
	this.list = list;
	inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
	return list.size();
    }

    @Override
    public Object getItem(int position) {
	return list.get(position);
    }

    @Override
    public long getItemId(int position) {
	return 0;
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
	ViewHolder holder = null;
	if (convertView == null) {
	    holder = new ViewHolder();
	    convertView = inflater.inflate(R.layout.item_spalarm, null);
	    holder.llalarm = (LinearLayout) convertView.findViewById(R.id.llalarm);
	    holder.spalarm = (TextView) convertView.findViewById(R.id.spalarm);
	    convertView.setTag(holder);
	} else {
	    holder = (ViewHolder) convertView.getTag();
	}
	holder.llalarm.setBackgroundResource(R.color.main);
	holder.spalarm.setText(list.get(position).getText());
	holder.spalarm.setTextColor(Color.BLACK);
	return convertView;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
	ViewHolder holder = null;
	if (convertView == null) {
	    holder = new ViewHolder();
	    convertView = inflater.inflate(R.layout.item_spalarm, null);
	    holder.llalarm = (LinearLayout) convertView.findViewById(R.id.llalarm);
	    holder.spalarm = (TextView) convertView.findViewById(R.id.spalarm);
	    convertView.setTag(holder);
	} else {
	    holder = (ViewHolder) convertView.getTag();
	}
	holder.llalarm.setBackgroundResource(R.color.darker);
	holder.spalarm.setText(list.get(position).getText());
	holder.spalarm.setTextColor(convertView.getResources().getColor(R.color.red));
	return convertView;
    }

    static class ViewHolder {

	LinearLayout llalarm;
	TextView spalarm;
    }
}
